package com.beiing.tianshuai.tianshuai.dongtai.model;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.DynamicAddReplyBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicCommentBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDeleteBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDetailBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicPraiseBean;
import com.beiing.tianshuai.tianshuai.entity.FollowBean;
import com.beiing.tianshuai.tianshuai.entity.FollowResultBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by magikliu on 2017/8/2.
 */

public class DynamicDetailModel implements DynamicDetailModelImpl {

    /**
     * 获取动态详情数据
     * @param uid
     * @param id
     */
    @Override
    public void getDynamicDetail(String uid, String id, int type, int page, int num, final CallBack callBack) {
        DisposableObserver<DynamicDetailBean> observer = new DisposableObserver<DynamicDetailBean>() {
            @Override
            public void onNext(@NonNull DynamicDetailBean dynamicDetailBean) {
                callBack.result(dynamicDetailBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getDynamicDetail(uid, id, type, page, num)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /**
     * 添加评论
     * @param uid
     * @param aid
     * @param content
     */
    @Override
    public void addComment(String uid, String to_uid, String aid, String content, String register_id, String create_time, final CallBack callBack) {
        DisposableObserver<DynamicCommentBean> observer = new DisposableObserver<DynamicCommentBean>() {
            @Override
            public void onNext(@NonNull DynamicCommentBean bean) {
                callBack.result(bean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDynamicCommentResult(uid, to_uid, aid, content, register_id, create_time)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /**
     * 回复评论
     *
     * @param did
     * @param cid
     * @param form_uid
     * @param to_uid
     * @param content
     * @param registration_id
     * @param callBack
     */
    @Override
    public void addReply(String did, String cid, String form_uid, String to_uid, String content, String registration_id, final CallBack callBack) {
        DisposableObserver<DynamicAddReplyBean> observer = new DisposableObserver<DynamicAddReplyBean>() {
            @Override
            public void onNext(@NonNull DynamicAddReplyBean dynamicAddReplyBean) {
                callBack.result(dynamicAddReplyBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDynamicAddReplyResult(did, cid, form_uid, to_uid, content, registration_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseDynamic(String userid, String aid, String to_uid, final CallBack callBack) {
        DisposableObserver<DynamicPraiseBean> observer = new DisposableObserver<DynamicPraiseBean>() {
            @Override
            public void onNext(@NonNull DynamicPraiseBean dynamicPraiseBean) {
                callBack.result(dynamicPraiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDynamicPraiseResult(userid, aid, to_uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteComment(String uid, String id, String did, final CallBack callBack) {
        DisposableObserver<DynamicDeleteBean> observer = new DisposableObserver<DynamicDeleteBean>() {
            @Override
            public void onNext(@NonNull DynamicDeleteBean dynamicDeleteBean) {
                callBack.result(dynamicDeleteBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getCommentDeleteResult(uid, id, did)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void isFollowed(String fromUid, String toUid, final CallBack callBack) {
        DisposableObserver<FollowBean> observer = new DisposableObserver<FollowBean>() {
            @Override
            public void onNext(@NonNull FollowBean followBean) {
                callBack.result(followBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.isFollowed(fromUid, toUid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void setFollowed(String fromUid, String toUid, final CallBack callBack) {
        DisposableObserver<FollowResultBean> observer = new DisposableObserver<FollowResultBean>() {
            @Override
            public void onNext(@NonNull FollowResultBean followResultBean) {
                callBack.result(followResultBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getFollowResult(fromUid, toUid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteReply(String uid, String id, final CallBack callBack) {
        DisposableObserver<DynamicDeleteBean> observer = new DisposableObserver<DynamicDeleteBean>() {
            @Override
            public void onNext(@NonNull DynamicDeleteBean dynamicDeleteBean) {
                callBack.result(dynamicDeleteBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getReplyDeleteResult(uid, id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseComment(String uid, String cid, String to_uid, String did, final CallBack callBack) {
        DisposableObserver<DynamicPraiseBean> observer = new DisposableObserver<DynamicPraiseBean>() {
            @Override
            public void onNext(@NonNull DynamicPraiseBean praiseBean) {
                callBack.result(praiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getDynamicCommentPraiseResult(uid, cid, to_uid, did)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void sendPush(String status, int tag, int id, String type, final CallBack callBack) {
        DisposableObserver<DynamicDeleteBean> observer = new DisposableObserver<DynamicDeleteBean>() {
            @Override
            public void onNext(DynamicDeleteBean deleteBean) {
                callBack.result(deleteBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getPushResult(status, tag, id, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
